﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Manage_SuperviseAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        { }
    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {

            HZ.MBSM.Model.Supervise Supervise = new HZ.MBSM.Model.Supervise();
            HZ.MBSM.Model.Account Account = new HZ.MBSM.Model.Account();

            int i = 0;
            if (Supervise != null)
            {                
                int rowCun=0;
                Db db = new Db();
                System.Data.IDataReader dr;
                String strSql = "select count(accountid) as cun from dbo.v_account where accountname='" + SysFun.ToTrim(AccountName.Text) + "'  or dwname= '" + SysFun.ToTrim(txtSuperviseName.Text) + "' or usercode='" + SysFun.ToTrim(txtUserCode.Text) + "'";
                dr = db.DataReader(strSql);
                if (dr.Read())
                {
                    rowCun = SysFun.ToInt(dr["cun"]);
                }
                dr.Close();
                dr.Dispose();
                db.Close();
                if (rowCun > 0)
                {
                    Response.Write("<script language=JavaScript>alert('该用户在数据库中已经存在！！！');</script>");
                }
                else
                {

                    Account.AccountName = SysFun.ToTrim(AccountName.Text);
                    Account.Pwd_Bid = SysFun.PasswordEncrypt(SysFun.ToTrim(Pwd_Bid.Text));
                    Account.Type = Convert.ToUInt16(HZ.MBSM.DAL.AccountType.enumSupervise).ToString();
                    Account.IsBid_Landing = "1";
                    Supervise.UserCode = SysFun.ToTrim(txtUserCode.Text);
                    Supervise.Address = SysFun.ToTrim(Address.Text);
                    Supervise.AreaId = SysFun.ToInt(Request.Form["AreaId"]);
                    Supervise.Class = RadioClass.SelectedValue.ToString();
                    Supervise.Email = SysFun.ToTrim(Email.Text);
                    Supervise.Fax = SysFun.ToTrim(Fax.Text);
                    Supervise.NetAddress = SysFun.ToTrim(NetAddress.Text);
                    Supervise.PostCode = SysFun.ToTrim(PostCode.Text);
                    Supervise.RegistDate =  System.DateTime.Today;
                    Supervise.SuperviseMan = SysFun.ToTrim(SuperviseMan.Text);
                    Supervise.SuperviseName = SysFun.ToTrim(txtSuperviseName.Text);
                    Supervise.Telephone = SysFun.ToTrim(Telephone.Text);
                    i = HZ.MBSM.BLL.UserRegist.RegistSupervise(Account, Supervise);
                    Response.Write("<script>alert('保存成功！！！');</script>");
                    i = i + 1;
                    HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "插入", "Supervise", Supervise.UserCode + "|" + Supervise.Address + "|" + Supervise.AreaId + "|" + Supervise.Class + "|" + Supervise.RegistDate, "../Magage/SuperviseAdd.aspx");

                    Response.Write("<script>window.opener.location.reload();window.close();</script>");
                }
            }
        }
    }

}
